package com.guohang.mic_01;

import android.app.Activity;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.Intent;
import android.os.Message;
import android.os.Messenger;
import android.util.Log;


public class BinManager {
   
	private Messenger messenger;
	private Context context;
	private Message backMsg = new Message();
	
	//constructor
	public BinManager(Messenger messenger, Context context){
		this.messenger = messenger;
		this.context = context;
	}
	
    public void updateUI(int count){
    	// current logic is if count of a cluster > 5, display UI 
    	// this will get more complex later when more constraints are implemented, or not, whatever.
    	if(count > 0){
			//start activity
			Intent dialogIntent = new Intent(context, ContextMIC.class);
			dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
			((Activity) context).getApplication().startActivity(dialogIntent);
			
			//send message to activity
			  try {
				    //just an empty message
				    backMsg.arg1= -1;
		            messenger.send(backMsg);
		          } catch (android.os.RemoteException e1) {
		            Log.w(getClass().getName(), "Exception sending message", e1);
		          }
    	}else{
    		return;
    	}
    }
}
